package com.anli.aopparam;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

/**
 * @author: LCG
 * @date: 2022-07-14 23:09:20
 * @description:
 **/

@Aspect
@Component
public class AopParamUpdateAspect {

    @Pointcut("@annotation(com.anli.aopparam.UpDateParam)")
    public void pointCut(){}

    @Around("pointCut()")
    public Object process(ProceedingJoinPoint point) throws Throwable {

        MethodSignature signature = (MethodSignature) point.getSignature();
        UpDateParam declaredAnnotation = signature.getMethod().getDeclaredAnnotation(UpDateParam.class);

        String paramName = declaredAnnotation.paramName();
        int paramIndex = declaredAnnotation.paramIndex();
        Object[] args = point.getArgs();

        args[paramIndex]="599999";

        return point.proceed(args);
    }

}
